package ch.upndown.upndown.utils;

import android.os.AsyncTask;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by DonMiguel on 13.09.2014.
 */
public class FindIconAsyncTask extends AsyncTask<Void, Void, String>{
    private String url;

    public FindIconAsyncTask(String url) {
        this.url = url;
    }

    @Override
    protected String doInBackground(Void... params) {
        InputStream is = null;
        BufferedInputStream bis = null;
        URLConnection conn = null;
        try {
            URL lurl = new URL(this.url);
            conn = lurl.openConnection();
            conn.connect();
            is = conn.getInputStream();
            bis = new BufferedInputStream(is);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (is != null){
                try {
                    is.close();
                } catch (IOException e) {}
            }
            if (bis != null){
                try {
                    bis.close();
                } catch (IOException e) {}
            }
        }
        return null;
    }

    private void wrapSourceCode(BufferedInputStream bis) throws IOException {

        byte[] contents = new byte[1024];

        int bytesRead=0;
        String strFileContents = null;
        while( (bytesRead = bis.read(contents)) != -1){
            strFileContents = new String(contents, 0, bytesRead);
        }
        System.out.print(strFileContents);
    }
}
